package com.liruan.rest.dao.lang;

import org.apache.ibatis.mapping.SqlSource;
import org.apache.ibatis.scripting.xmltags.XMLLanguageDriver;
import org.apache.ibatis.session.Configuration;

public class BaseDriver extends XMLLanguageDriver
{
	private static final String XML_GREATER = " &gt; ";
	private static final String XML_LESS = " &lt; ";
	private static final String SQL_GREATER = ">";
	private static final String SQL_LESS = "<";
	private static final String SCRIPT_OPEN = "<script>";
	private static final String SCRIPT_CLOSE = "</script>";

	@Override
	public SqlSource createSqlSource(Configuration configuration, String script,
	        Class<?> parameterType)
	{
		script.replaceAll(SQL_GREATER, XML_GREATER);
		script.replaceAll(SQL_LESS, XML_LESS);
		script = SCRIPT_OPEN + script + SCRIPT_CLOSE;
		return super.createSqlSource(configuration, script, parameterType);
	}
}
